package cn.edu.sasu.controller;


import cn.edu.sasu.common.annotation.RoleNum;
import cn.edu.sasu.common.base.LayuiRespResult;
import cn.edu.sasu.common.base.RespResult;
import cn.edu.sasu.common.constants.Role;
import cn.edu.sasu.domain.entity.SysMenu;
import cn.edu.sasu.domain.vo.SysUserInfoVO;
import cn.edu.sasu.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王尧
 * @since 2024-04-28
 */
@RestController
@RequestMapping("/api/sys_menu")
public class SysMenuController {



    @Autowired
    private ISysMenuService menuService;
    


    /*查询系统菜单*/
    @RoleNum(Role.COMMON)
    @GetMapping("/findSysMenuAll")
    public LayuiRespResult findSysMenuAll(Integer page, Integer limit) {
        return menuService.findSysMenuAll(page, limit);
    }


    /*根据菜单的名称查询*/
    @RoleNum(Role.COMMON)
    @GetMapping("/search")
    public LayuiRespResult search(Integer page,Integer limit,String menuName){
        return menuService.search(page,limit,menuName);
    }



    /*添加菜单信息*/
    @RoleNum(Role.COMMON)
    @PostMapping("/save")
    public RespResult save(@RequestBody SysMenu menu){
        return menuService.save(menu);
    }


    /*获取所有的菜单*/
    @GetMapping("/findSysMenus")
    public LayuiRespResult findSysMenus(){
        return menuService.findSysMenus();
    }


    /*根据id删除菜单*/
    @RoleNum(Role.ADMIN)
    @PostMapping("/del")
    public RespResult del(Integer menuId){
        return menuService.delSysMenuByMenuId(menuId);
    }

    /*根据id集合，批量删除*/
    @RoleNum(Role.ADMIN)
    @PostMapping("/batchdel")
    public RespResult batchdel(Integer[] menuIds){
        return menuService.batchdel(menuIds);
    }


    @PostMapping("/updateInfo")
    public RespResult updateInfo(@RequestBody SysMenu menu){
        return menuService.updateInfo(menu);
    }



}
